<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>Document</title>
</head>
<body>
	<form action="" id="t" onsubmit=" return validate()">
		name: <input type="text" name="name">
		password: <input type="password" name="password">
		<input type="submit" value="submit">
	</form>
</body>
<script>
	
	function validate() {
		var form = document.getElementsByTagName("form");
		with(form[0]) {
			if(name.value == "") {
				alert("name can't be null");
				return false;
			}
			return true;
		}
	}
</script>
</html>